/* Copyright 2009 Sony Mathew, Minneapolis MN. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
package com.xsm.swing;

import java.awt.Component;

import javax.swing.Box;
import javax.swing.BoxLayout;

/**
 * Base class for all Boxes that the AxisPanel uses including itself.
 * 
 * @author Sony Mathew
 */
public abstract class AxisPanelBox extends Box {

    private final int axis;
    
    /**
     * Provide the axis from BoxLayout to use. 
     * 
     * author Sony Mathew
     */
    public AxisPanelBox(int axis) {
        super(axis);
        this.axis = axis;        
        if (!isAxisX() && !isAxisY()) {
            throw new IllegalStateException("Bad Axis [" + axis + "]");
        }        
    }
    
    public boolean isAxisX() {
        return axis == BoxLayout.X_AXIS;
    }
    
    public boolean isAxisY() {
        return axis == BoxLayout.Y_AXIS;
    }
    
    public int getAxis() {
        return axis;
    }
    
    /**
     * Creates the appropriate struct for our axis (vertical or horizontal).
     *  
     * @param size: either width or height depending on axis.
     * 
     * author Sony Mathew
     */
    public Component createAxisStrut(int size) {
        if (isAxisX()) {
            return Box.createHorizontalStrut(size);
        }else if (isAxisY()) {
            return Box.createVerticalStrut(size);
        }else{
            throw new IllegalStateException("Bad Axis [" + axis + "]");
        }
    }
}
